package com.decorator.springcloud.controller;

import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

@RestController
public class KafkaClusterController {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    @GetMapping("/sendMsg")
    public void sendMsg() {

        for (int i = 0; i < 10; i++) {

            ListenableFuture testSendTopic = kafkaTemplate.send("testSendTopic", "无主题发送消息" + i);
            if (testSendTopic.isDone()) {
                CompletableFuture completable = testSendTopic.completable();

            }

        }

        for (int i = 0; i < 10; i++) {
            kafkaTemplate.send(new ProducerRecord<String, String>("my-topic", "hello" + i, "java" + i));
        }

    }
}
